﻿
// 2018/6/20: 首个记录
// 2018/12/29: 改pragma once
// 2019/3/29: 添加注释
// 2019/10/11: 修改include
// 2020/1/13: 接口完备性
// 2020/5/15: 修正fromGeneralSample
// 2020/11/12: 支持Spadas7
// 2022/11/2: 支持Spadas8.4
// 2023/10/11: 补充部分英文注释

#ifndef MAN_TRIGGER_SAMPLE_V1_H
#define MAN_TRIGGER_SAMPLE_V1_H

#include "spadas.h"

namespace man_trigger_sample_v1
{
	using namespace spadas;

	struct ManTriggerSample
	{
		FullTimestamp timestamp; // 时间戳
		Bool triggers[16]; // Weather each channel of manual trigger is activated / 16路手动触发器是否激活

		ManTriggerSample()
		{
			for (UInt i = 0; i < 16; i++) triggers[i] = FALSE;
		}

		static String getProtocolName()
		{
			return "man-trigger-sample-v1";
		}

		static Bool supportInterpolation()
		{
			return FALSE;
		}

		SessionGeneralSample toGeneralSample()
		{
			SessionGeneralSample sample;
			sample.timestamp = timestamp;
			sample.values = Array<GeneralElement>(16);
			GeneralElement *data = sample.values.data();

			for (UInt i = 0; i < 16; i++)
			{
				data[i] = triggers[i] ? 1 : 0;
			}

			return sample;
		}

		Bool fromGeneralSample(String protocol, SessionGeneralSample sample)
		{
			timestamp = sample.timestamp;

			if (protocol == "man-trigger-sample-v1")
			{
				if (sample.values.size() != 16) return FALSE;

				for (UInt i = 0; i < 16; i++)
				{
					triggers[i] = sample.values[i].value == 1;
				}

				return TRUE;
			}

			return FALSE;
		}

		static ManTriggerSample interpolate(ManTriggerSample& s1, Double w1, ManTriggerSample& s2, Double w2, FullTimestamp timestamp)
		{
			return ManTriggerSample();
		}
	};
}

#endif
